/*
Copyright (C) <2011>  <ivan vaccari>

    <ivan.vaccari@studenti.unipr.it>


This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.


*/
#include "turingConfiguration.h"
#include <string>
#include "instruction.h"
#include <fstream>
turingConfiguration::turingConfiguration(){

}
void turingConfiguration::setName(const std::string & _name){
    name=_name;
}

std::string turingConfiguration::getName() const{
    return name;
}
void turingConfiguration::addInstruction(const std::string & instr){

    /*todo: check if another instruction already exists*/
    instruction i(instr);
    if (i.isValid()){
        instructions.push_back(i);
    }
}
void turingConfiguration::setInitialState(const std::string & _initState){
    /*todo:check if exist _initState in states list*/
    initialState=_initState;
}
std::string turingConfiguration::getInitialState() const{
    return initialState;

}
bool turingConfiguration::findInstruction(const std::string & state,const std::string &symbol, instruction &ins) const{
    for(std::list<instruction>::const_iterator i=instructions.begin();i!=instructions.end();++i){
        if (i->match(state,symbol)){
            ins=*i;
            return true;
        }

    }
    return false;
}

